<?php

namespace App\Http\Controllers\Ajax;

use App\Common\Constant\Status;
use App\Services\IOrderService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OrderController extends BaseController
{

    /**
     * 预约上门时间
     * @param Request $request
     * @param IOrderService $orderService
     * @return \Illuminate\Http\JsonResponse
     */
    public function appoint(Request $request,IOrderService $orderService)
    {
        if ($request->isMethod('post') && $request->has('order_id') && $request->has('door_time')){
            $ret = $orderService->appoint($request->input('order_id'),$request->input('door_time'));
            return $this->renderJson($ret ? Status::SUCCESS : Status::FAIL);
        }

        return $this->renderJson(Status::ERROR);
    }

    /**
     * 师傅对订单备注
     * @param Request $request
     * @param IOrderService $orderService
     * @return \Illuminate\Http\JsonResponse
     */
    public function mark(Request $request,IOrderService $orderService)
    {
        if ($request->isMethod('post') && $request->has('order_id')){
            $ret = $orderService->mark($request->input('order_id'),getCurrentUserid(),$request->input('mark'));
            return $this->renderJson($ret ? Status::SUCCESS : Status::FAIL);
        }

        return $this->renderJson(Status::ERROR);
    }

    /**
     * 师傅对评价回复
     * @param Request $request
     * @param IOrderService $orderService
     */
    public function reply(Request $request,IOrderService $orderService)
    {
        if ($request->isMethod('post') && $request->has('order_id')){
            $ret = $orderService->reply($request->input('order_id'),$request->input('reply'));
            return $this->renderJson($ret ? Status::SUCCESS : Status::FAIL);
        }

        return $this->renderJson(Status::ERROR);
    }

    /**
     * 师傅的全部订单列表，包括商家选定该师傅雇佣后所有正常状态、异常状态的订单
     * @param Request $request
     * @param IOrderService $orderService
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function listMasterAll(Request $request,IOrderService $orderService)
    {
        $page = $request->input('page',1);
        $listMasterAll = $orderService->listMasterAll(getCurrentUserid(),$page);
        return view('order/layouts/orderList-inner',['list'=>$listMasterAll,'page'=>$page]);
    }

    /**
     * 师傅的已报价订单列表
     * @param $order_id
     * @param Request $request
     * @param IOrderService $orderService
     */
    public function listMasterOffered(Request $request,IOrderService $orderService)
    {
        $page = $request->input('page',1);
        $listMasterOffered = $orderService->listMasterOffered(getCurrentUserid(),$page);
        return view('order/listMasterOffered-inner',['list'=>$listMasterOffered,'page'=>$page]);
    }
}
